
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 12/02/2013 19:11:35
-- Generated from EDMX file: E:\Projects\Visual Studio\Excell On Services\02_IMPLEMENTATION\BackEnd\Model.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [ExcellOnServices];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------


-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------


-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Products'
CREATE TABLE [dbo].[Products] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Image] nvarchar(max)  NOT NULL,
    [Price] nvarchar(max)  NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [Properties] nvarchar(max)  NOT NULL,
    [CreatedDateTime] nvarchar(max)  NOT NULL,
    [ModifiedDateTime] nvarchar(max)  NOT NULL,
    [Company_Id] int  NOT NULL
);
GO

-- Creating table 'Services'
CREATE TABLE [dbo].[Services] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [Price] nvarchar(max)  NOT NULL,
    [Properties] nvarchar(max)  NOT NULL,
    [CreatedDateTime] nvarchar(max)  NOT NULL,
    [ModifiedDateTime] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'OrderItems'
CREATE TABLE [dbo].[OrderItems] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [ServicePrice] nvarchar(max)  NOT NULL,
    [Product_Id] int  NOT NULL,
    [Service_Id] int  NOT NULL,
    [Order_Id] int  NOT NULL
);
GO

-- Creating table 'Orders'
CREATE TABLE [dbo].[Orders] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [BeginDateTime] nvarchar(max)  NOT NULL,
    [EndDateTime] nvarchar(max)  NOT NULL,
    [Status] nvarchar(max)  NOT NULL,
    [Payment] nvarchar(max)  NOT NULL,
    [Properties] nvarchar(max)  NOT NULL,
    [CreatedDateTime] nvarchar(max)  NOT NULL,
    [ModifiedDateTime] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Accounts'
CREATE TABLE [dbo].[Accounts] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Address] nvarchar(max)  NOT NULL,
    [Email] nvarchar(max)  NOT NULL,
    [Password] nvarchar(max)  NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [Properties] nvarchar(max)  NOT NULL,
    [CreatedDateTime] nvarchar(max)  NOT NULL,
    [ModifiedDateTime] nvarchar(max)  NOT NULL,
    [Roles_Id] int  NOT NULL
);
GO

-- Creating table 'Roles'
CREATE TABLE [dbo].[Roles] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Description] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Accounts_Company'
CREATE TABLE [dbo].[Accounts_Company] (
    [Id] int  NOT NULL
);
GO

-- Creating table 'Accounts_Admin'
CREATE TABLE [dbo].[Accounts_Admin] (
    [Id] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'Products'
ALTER TABLE [dbo].[Products]
ADD CONSTRAINT [PK_Products]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Services'
ALTER TABLE [dbo].[Services]
ADD CONSTRAINT [PK_Services]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'OrderItems'
ALTER TABLE [dbo].[OrderItems]
ADD CONSTRAINT [PK_OrderItems]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Orders'
ALTER TABLE [dbo].[Orders]
ADD CONSTRAINT [PK_Orders]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Accounts'
ALTER TABLE [dbo].[Accounts]
ADD CONSTRAINT [PK_Accounts]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Roles'
ALTER TABLE [dbo].[Roles]
ADD CONSTRAINT [PK_Roles]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Accounts_Company'
ALTER TABLE [dbo].[Accounts_Company]
ADD CONSTRAINT [PK_Accounts_Company]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Accounts_Admin'
ALTER TABLE [dbo].[Accounts_Admin]
ADD CONSTRAINT [PK_Accounts_Admin]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Company_Id] in table 'Products'
ALTER TABLE [dbo].[Products]
ADD CONSTRAINT [FK_CompanyProduct]
    FOREIGN KEY ([Company_Id])
    REFERENCES [dbo].[Accounts_Company]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CompanyProduct'
CREATE INDEX [IX_FK_CompanyProduct]
ON [dbo].[Products]
    ([Company_Id]);
GO

-- Creating foreign key on [Product_Id] in table 'OrderItems'
ALTER TABLE [dbo].[OrderItems]
ADD CONSTRAINT [FK_ProductBusiness]
    FOREIGN KEY ([Product_Id])
    REFERENCES [dbo].[Products]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ProductBusiness'
CREATE INDEX [IX_FK_ProductBusiness]
ON [dbo].[OrderItems]
    ([Product_Id]);
GO

-- Creating foreign key on [Service_Id] in table 'OrderItems'
ALTER TABLE [dbo].[OrderItems]
ADD CONSTRAINT [FK_ServiceBusiness]
    FOREIGN KEY ([Service_Id])
    REFERENCES [dbo].[Services]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ServiceBusiness'
CREATE INDEX [IX_FK_ServiceBusiness]
ON [dbo].[OrderItems]
    ([Service_Id]);
GO

-- Creating foreign key on [Roles_Id] in table 'Accounts'
ALTER TABLE [dbo].[Accounts]
ADD CONSTRAINT [FK_AccountRole]
    FOREIGN KEY ([Roles_Id])
    REFERENCES [dbo].[Roles]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AccountRole'
CREATE INDEX [IX_FK_AccountRole]
ON [dbo].[Accounts]
    ([Roles_Id]);
GO

-- Creating foreign key on [Order_Id] in table 'OrderItems'
ALTER TABLE [dbo].[OrderItems]
ADD CONSTRAINT [FK_OrderBusiness]
    FOREIGN KEY ([Order_Id])
    REFERENCES [dbo].[Orders]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_OrderBusiness'
CREATE INDEX [IX_FK_OrderBusiness]
ON [dbo].[OrderItems]
    ([Order_Id]);
GO

-- Creating foreign key on [Id] in table 'Accounts_Company'
ALTER TABLE [dbo].[Accounts_Company]
ADD CONSTRAINT [FK_Company_inherits_Account]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[Accounts]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'Accounts_Admin'
ALTER TABLE [dbo].[Accounts_Admin]
ADD CONSTRAINT [FK_Admin_inherits_Account]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[Accounts]
        ([Id])
    ON DELETE CASCADE ON UPDATE NO ACTION;
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------